package com.congwulin.wechat.util;

import com.congwulin.wechat.entity.common.AbstractMeBillVO;
import com.congwulin.wechat.entity.common.CommonJSonData;
import com.congwulin.wechat.entity.common.SuperVO;

import java.util.*;

public class BillTransJSonUtil {
    public static CommonJSonData transJSon(List<? extends AbstractMeBillVO> bills) {
        CommonJSonData data = new CommonJSonData();
        List<LinkedHashMap> list = new ArrayList<LinkedHashMap>();
        LinkedHashMap<String, List<SuperVO>> voHashMap = null;
        for(AbstractMeBillVO bill: bills){
            SuperVO head = bill.getHead();
            Map<Class<?>,List<SuperVO>> bodys = bill.getChildrens();
            Map<String, Class<?>> names = bill.getAreaNameIndex();
            voHashMap = new LinkedHashMap<String, List<SuperVO>>();
            for(String areaname: names.keySet()){
                voHashMap.put(areaname, bodys.get(names.get(areaname)));
            }
            List<SuperVO> headList = new ArrayList<SuperVO>();
            headList.add(head);
            voHashMap.put("head",headList);
            list.add(voHashMap);
        }
        data.setData(list);
        return data;
    }
}
